package com.example.rk.controller;

import com.example.rk.common.MyPageInfo;
import com.example.rk.common.SessionParameter;
import com.example.rk.entity.Admin;
import com.example.rk.entity.Job;
import com.example.rk.entity.Resume;
import com.example.rk.service.JobService;
import com.example.rk.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/resume")
public class ResumeController     
  
 {
    @Autowired
    @Resource
    private ResumeService service;
    @RequestMapping("/list")
    public ModelAndView xslb(HttpServletRequest request, ModelAndView mv) {
        Admin admin = (Admin) request.getSession().getAttribute(SessionParameter.ADMIN_INFO);
        MyPageInfo myPageInfo = service.findBySearch(request,admin.getId());
        mv.addObject("searchtitle", request.getParameter("title"));
        mv.addObject("pageInfo", myPageInfo);
        mv.setViewName("/xs/resumelist");
        return mv;
    }
    @RequestMapping("/list2/{id}")
    public ModelAndView xslb2(HttpServletRequest request, ModelAndView mv,@PathVariable("id") int id) {
        MyPageInfo myPageInfo = service.findBySearch1(request,id);
        mv.addObject("searchtitle", request.getParameter("title"));
        mv.addObject("pageInfo", myPageInfo);
        mv.setViewName("/gs/resumelist");
        return mv;
    }
    @RequestMapping("/doEdit1/{id}")
    public String doEdit1(@PathVariable("id") int id) {
        service.doEdit1(id);
        return "redirect:/resume/list";
    }
    @RequestMapping("/doEdit2/{id}")
    public String doEdit2(@PathVariable("id") int id) {

      service.doEdit2(id);
        return "redirect:/resume/list";
    }
    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable("id") int id) {
        service.deleteById(id);
        return "redirect:/resume/list";
    }
    @RequestMapping("/doAdd")
    @ResponseBody
    public String doAdd(Resume resume,HttpServletRequest request) {
        Admin admin = (Admin) request.getSession().getAttribute(SessionParameter.ADMIN_INFO);
        resume.setSid(admin.getId());
        resume.setZt(0);
        return service.doAdd(resume);
    }
    @RequestMapping("/openEdit/{id}")
    public ModelAndView openEdit(@PathVariable("id") int id, ModelAndView mv,HttpServletRequest request) {
        Resume resume = service.findById(id);
        Admin admin = (Admin) request.getSession().getAttribute(SessionParameter.ADMIN_INFO);
        mv.addObject("resume", resume);
        mv.setViewName("/xs/resumeedit");
        return mv;
    }
    @RequestMapping("/doEdit")
    @ResponseBody
    public String doEdit(Resume resume) {
        return service.doEdit(resume);
    }
    @RequestMapping("/search/{id}")
    public ModelAndView search(@PathVariable("id") int id, ModelAndView mv) {
        Resume resume = service.findById(id);
        mv.addObject("resume", resume);
        mv.setViewName("/gs/resume");
        return mv;
    }

}

